#!/bin/bash

set -e

name="jetty"
v1="9.2.22"
v2="jdk8u171"

r="${name}:${v1}-${v2}"

ID=$(docker images | grep ${name} | grep ${v1}-${v2} | awk '{print $3}')
if [ "$ID" != "" ] ; then
    echo "Image $r[$ID] already exists"
    exit 1;
fi

chmod +x Dockerfile
docker build --no-cache=true -t ${r} -f Dockerfile . $@ 2>&1 | tee build.log
IMAGE=$(tail -1 build.log | awk '{ print $NF }')
docker tag ${IMAGE} 203.195.221.134:5000/$r
docker push 203.195.221.134:5000/$r